package presentationTier.actions;

import businessTier.IMovieFacade;
import businessTier.MovieFacade;
import core.Genre;
import core.Medium;
import core.Movie;
import core.MovieException;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.List;
import presentationTier.Global;
import presentationTier.MainForm;
import presentationTier.dialogs.SearchMovieDialog;

/**
 *
 * @author vojta
 */
public class SearchMovieOkAction implements ActionListener{

    SearchMovieDialog dialog;

    public SearchMovieOkAction(SearchMovieDialog aThis) {
        dialog = aThis;
    }

    public void actionPerformed(ActionEvent e) {
        MainForm form = (MainForm) dialog.getParent();
        try {
            String name = dialog.txtName.getText();
            String director = dialog.txtDirector.getText();
            String year_h = dialog.txtYear.getText();
            int year = 0;
            if (!year_h.equals("")) {
                year = Integer.parseInt(year_h);
            }
            Medium medium = (Medium) dialog.comboBoxMedium.getSelectedItem();
            Genre genre = (Genre) dialog.comboBoxGenre.getSelectedItem();
            Movie movie = new Movie(name, year, director, medium, genre);            
            IMovieFacade mf = MovieFacade.getInstance();
            List<Movie> list = mf.findMovies(movie);

            Global.setTableModel(list, form);
            dialog.dispose();

        } catch (MovieException ex) {
            form.error(ex);
            ex.printStackTrace();
        }

    }

}
